﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <algorithm>
#include <ios>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

int vis[1001] = { 0 };
int mini = INT_MAX;

bool isPrime(int num)
{
    for (int i = 2; i <= sqrt(num); i++) if (num % i == 0) return false;
    return true;
}

void kotori(vector<int>& arr, int index, int sum)
{
    if (index == arr.size())
    {
        mini = min(sum, mini);
        return;
    }

    for (int i = 2; i <= arr[index]; i++)
    {
        if (arr[index] % i == 0 && isPrime(i) && vis[i] == 0)
        {
            vis[i] = 1;
            sum += i;
            kotori(arr, index + 1, sum);
            sum -= i;
            vis[i] = 0;
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];

    kotori(arr, 0, 0);
    if (mini == INT_MAX) cout << -1;
    else cout << mini;
    return 0;
}
// 64 位输出请用 printf("%lld")
//1 1 1
//1 0 0
//1 0 0
//1 0 0